<script>
	const index = require('@/api/personal/index.js')
	export default {
		data() {
			return {
				// projectId:''
			}
		},
		onLoad(options) {},
		async onLaunch() {
			// this.cloud()
			uni.removeStorageSync('tarbar_index')
			console.log('App Launch')
			await this.initData();
		},
		onShow: function() {
			console.log('App Show')
			// getApp().globalData.projectId,globalData.projectId
		},
		onHide: function() {
			console.log('App Hide')
			if (uni.getStorageSync("fenx")) {
				this.getPointsByZhuanFa()
			}
		},
		methods: {
			cloud() {
				wx.cloud.callFunction({
					name: 'generateQrCode',
					data: {
						scene: '15651039802', // 传递推荐人ID作为参数
						page: 'pages/index/index', // 小程序码跳转的页面路径
						width: 280 // 小程序码的宽度
					},
					success: res => {
						console.log(res, '11111')
						// 接口调用成功，获取生成的小程序码
						const qrCodeUrl = res.result.qrCodeUrl;
						// 将小程序码展示给用户
						// ...
					},
					fail: err => {
						// 接口调用失败
						console.error(err);
					}
				});
			},
			// 数据初始化
			async getPointsByZhuanFa() {
				let datas = {
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
					open_id: uni.getStorageSync("openid"),
				};
				index.getPointsByZhuanFa(datas).then(result => {
					if (result.code == 1) {
						uni.removeStorage({
							key: 'fenx',
							success: function(res) {}
						});
					}
				})
			},
			// 数据初始化
			async initData() {
				// 获取页面设置配置
				const _this = this;
				// 获取学员资料
				let params = {
					app_id: this.$https.weixinAppId,
				}
				// let res = await venues.getProjectIdByAppId(params)
				index.getProjectIdByAppId(params).then(result => {
					// _this.globalData.projectId = result.data.result
					// getApp().globalData.projectId = result.data.result
					getApp().globalData.projectId = result.data.result
					getApp().globalData.sign = result.data.sign;
					let buy_success = result.data.template_ids.buy_success //购买通知id
					let refund_success = result.data.template_ids.refund_success //退款通知id
					let share_success = result.data.template_ids.share_success //分享通知id
					let class_begin = result.data.template_ids.class_begin //分享通知id
					let template_ids = result.data.template_ids //分享通知id
					uni.setStorageSync('buy_success_id', buy_success)
					uni.setStorageSync('refund_success_id', refund_success)
					uni.setStorageSync('share_success_id', share_success)
					uni.setStorageSync('class_begin_id', class_begin)
					uni.setStorageSync('template_ids', template_ids)
					console.log(uni.getStorageSync("template_ids"), '789')

					// uni.setStorageSync('projectId',result.data.result)

				})
			},

			onShareAppMessage: function(res) {
				// let rushList = this.data.rushList;
				// let cate_info = rushList && rushList[0].cate_info;
				// var share_title = (cate_info && cate_info.name) || '分类列表';
				var share_title = '五点科技';
				var share_id = 1212;
				var id = 9999;
				var share_path = `page_points/page_points/points_mall?id=${id}&share_id=${share_id}`;

				return {
					title: share_title,
					path: share_path,
					success: function(res) {
						// 转发成功
					},
					fail: function(res) {
						// 转发失败
					}
				}
			}

		},
		globalData: {
			projectId: '',

		},

	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>